//
//  QianBaoSegmTableViewCell.m
//  DBAChain
//
//  Created by Evan on 2018/9/9.
//  Copyright © 2018 Evan. All rights reserved.
//

#import "QianBaoSegmTableViewCell.h"
#import "CommonData.h"
#import <Masonry.h>

@implementation QianBaoSegmTableViewCell{
    CGFloat tab1xx;
    CGFloat tab2xx;
    CGFloat tab3xx;
}

+ (instancetype)cellWithTableView:(UITableView *)tableView IndexPath:(NSIndexPath *)indexPath
{
    NSString *Service = [NSString stringWithFormat:@"QianBaoSegmTableViewCell_%ld_%ld",indexPath.section,indexPath.row];
    QianBaoSegmTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:Service];
    if (cell == nil) {
        [tableView registerClass:[QianBaoSegmTableViewCell class] forCellReuseIdentifier:Service];
        cell = [tableView dequeueReusableCellWithIdentifier:Service];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        [cell initUI];
    }
    return cell;
}

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

-(void)initUI{
    
    [self segmCheck];
    [self segmCheckIMG];
}

#pragma mark - Segm

-(UIImageView*)segmCheckIMG{
    if (!_segmCheckIMG) {
        _segmCheckIMG = [[UIImageView alloc]init];
        [self addSubview:_segmCheckIMG];
        tab1xx = ((KScreenWidth-30)/3-60)/2 + 15;
        tab2xx = (KScreenWidth-30)/3+ tab1xx;
        tab3xx = (KScreenWidth-30)/3+ tab2xx;
        _segmCheckIMG.frame = CGRectMake(tab1xx, 32, 60, 2);
        _segmCheckIMG.image = [UIImage imageNamed:@"矩形Line"];
    }
    return _segmCheckIMG;
}

-(UISegmentedControl*)segmCheck{
    if (!_segmCheck) {
        _segmCheck = [[UISegmentedControl alloc]initWithItems:@[@"全部记录",@"充值记录",@"提币记录"]];
        [self addSubview:_segmCheck];
        [_segmCheck mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerX.mas_equalTo(self);
            make.top.mas_equalTo(self).offset(0);
            make.height.offset(30);
            make.width.mas_equalTo(self).offset(-30);
        }];
        _segmCheck.tintColor = [UIColor clearColor];
        NSDictionary *selected = @{NSFontAttributeName:[UIFont systemFontOfSize:15],NSForegroundColorAttributeName:LCFromRGB(240, 92, 164)};
        //定义未选中状态下的样式normal，类型为字典
        NSDictionary *normal = @{NSFontAttributeName:[UIFont systemFontOfSize:15],NSForegroundColorAttributeName:LCFromRGB(51, 51, 51)};
        [_segmCheck setTitleTextAttributes:normal forState:UIControlStateNormal];
        [_segmCheck setTitleTextAttributes:selected forState:UIControlStateSelected];
        
        _segmCheck.selectedSegmentIndex = 0;
        [_segmCheck addTarget:self action:@selector(segmentValueChanged:)forControlEvents:UIControlEventValueChanged];
    }
    return _segmCheck;
}

-(void)segmentValueChanged:(UISegmentedControl*)sender{
    switch (sender.selectedSegmentIndex) {
        case 0:
            {
                [UIView animateWithDuration:0.3 animations:^{
                    self.segmCheckIMG.frame = CGRectMake(self->tab1xx, self.segmCheckIMG.frame.origin.y, 60, 2);
                }];
            }
            break;
        case 1:
        {
            [UIView animateWithDuration:0.3 animations:^{
                self.segmCheckIMG.frame = CGRectMake(self->tab2xx, self.segmCheckIMG.frame.origin.y, 60, 2);
            }];
        }
            break;
        case 2:
        {
            [UIView animateWithDuration:0.3 animations:^{
                self.segmCheckIMG.frame = CGRectMake(self->tab3xx, self.segmCheckIMG.frame.origin.y, 60, 2);
            }];
        }
            break;
        default:
            break;
    }
}



@end
